package com.chen10.cattle.ws.pojo;

import com.chen10.cattle.common.constants.GameConstants;
import com.chen10.cattle.common.enums.game.PlayerColorEnums;
import com.chen10.cattle.model.vo.PlayerInfoVO;
import lombok.Data;

import java.util.Arrays;
import java.util.List;

@Data
public class Room {

    public static final int BOARD_SIZE = GameConstants.BOARD_SIZE; // 假设五子棋棋盘大小为15x15
    private String roomId; // 房间ID
    private List<PlayerInfoVO> playerInfoList; // 玩家们的信息
    private Integer currentPlayerColor; // 当前轮到的玩家颜色
    private Integer currentPlayerId; // 当前轮到的玩家id
    private int[][] board; // 棋盘状态
    private String status; // 房间状态
    private boolean isMatchMode = false;

    /**
     * 初始化游戏数据
     */
    public void initGame() {
        //初始化棋盘
        this.board = new int[BOARD_SIZE][BOARD_SIZE]; // 初始化棋盘数据
        for (int i = 0; i < BOARD_SIZE; i++) {
            Arrays.fill(this.board[i], 0); // 初始化为0
        }

        //初始化玩家信息
        this.currentPlayerId = getPlayerInfoList().get(0).getUserId();
        this.currentPlayerColor = PlayerColorEnums.BLACK.getCode();
        this.getPlayerInfoList().get(0).setPlayerColor(PlayerColorEnums.BLACK.getCode());
        this.getPlayerInfoList().get(1).setPlayerColor(PlayerColorEnums.WHITE.getCode());
    }

    /**
     * 创建房间初始化房间（还未初始化游戏）
     */
    public void creatRoom(){

    }
    public boolean isRoomPlayer(Integer playerUserId) {
        for (PlayerInfoVO playerInfoVO : playerInfoList) {
            if (playerInfoVO.getUserId().equals(playerUserId)) {
                return true;
            }
        }
        return false;
    }
}
